package com.slofzx.nuoda.sso.controller;

import com.slofzx.nuoda.common.util.IPUtil;
import com.slofzx.nuoda.common.vo.AjaxResultVO;
import com.slofzx.nuoda.sso.dto.SsoLoginDTO;
import com.slofzx.nuoda.sso.service.SsoLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 单点登录控制器
 * @author sunfuyong
 */
@RestController
@RequestMapping("/sso_login")
public class SSOLoginController {

    @Autowired
    private SsoLoginService ssoLoginService;
    @GetMapping("/get_token")
    public AjaxResultVO<String> getToken(SsoLoginDTO dto, HttpServletRequest request) {
        String ip = IPUtil.getIpAddr(request);
        if(dto!=null) {
            dto.setClientIp(ip);
        }
        return AjaxResultVO.newSuccessResult(ssoLoginService.getToken(dto));
    }
    @GetMapping("/check_token")
    public AjaxResultVO<String> checkToken(SsoLoginDTO dto) {
        return AjaxResultVO.newSuccessResult(ssoLoginService.checkToken(dto));
    }
}
